package nlg
import(
	"sync"
)
type robotNlgMgr struct {
	Id2RobotMap map[string] *robotNlg
}
type robotNlg struct{
	 State2ResponseMap map[string] string
}
var once sync.Once
var pNlgMgr *robotNlgMgr
func GetNlgMgr() *robotNlgMgr{
	once.Do (func() {
		pNlgMgr  =  createNlgMgr()
	})
	return pNlgMgr
}
func createNlgMgr() *robotNlgMgr{
	newNlgMgr := new (robotNlgMgr)
	newNlgMgr.Id2RobotMap = make(  map[string] *robotNlg)
	return newNlgMgr
}

func GetRobotNlg(mgr *robotNlgMgr, robotId string) * robotNlg{
	inst,ok := mgr.Id2RobotMap[robotId]
	if (!ok){
		inst = SetupRobotNlg(mgr,robotId)
	}
	return inst
}
func SetupRobotNlg (mgr *robotNlgMgr, robotId string) * robotNlg{
robotNlgInst := new (robotNlg)
robotNlgInst.State2ResponseMap  = make(  map[string] string)
robotNlgInst.State2ResponseMap["welcome"]="您好"
robotNlgInst.State2ResponseMap["order"]="下单"
robotNlgInst.State2ResponseMap["query"]="查询"
mgr.Id2RobotMap[robotId] = robotNlgInst
return robotNlgInst
}

func GetResponse(nlgInst *robotNlg,state string) string{
	res,ok := nlgInst.State2ResponseMap[state]
	if (!ok){
		res = "I am sorry, I do not know, I will continue to study it!"
	}
	return res
}
